package org.reliablesource.prism.ui.workbench.actions;

/**
 *  
 *  Copyright (c) 2006, Reliable Source, Inc. All Rights Reserved
 *
 *	Created on: Mar 15, 2006
 *  @author Dennis Park <a href="mailto:dennis.park@gmail.com">dennis.park@gmail.com</a>
 *
 */

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.PartInitException;
import org.reliablesource.prism.ui.viewers.AnimationViewer;
import org.reliablesource.prism.ui.workbench.views.AnimationViewPart;

public class AnimateAction extends Action implements IWorkbenchWindowActionDelegate,
		IObjectActionDelegate{
	private IWorkbenchWindow window;
	private IStructuredSelection selection;
	private IWorkbenchPart part;
	
	public AnimateAction(){
		super();
	}
	
	public void dispose() {
	}

	public void init(IWorkbenchWindow _window) {
		window = _window;
	}

	public void run(IAction _action) {
		try {
			part = window.getActivePage().showView(AnimationViewPart.VIEW_ID);
			((AnimationViewer)((AnimationViewPart)part).getContentViewer()).startAnimation();
		} catch (PartInitException e) {
			e.printStackTrace();
		}
	}


	public void selectionChanged(IAction _action, ISelection _selection) {
		selection = (StructuredSelection) _selection;
		_action.setEnabled(false);
	}

	public void setActivePart(IAction _action, IWorkbenchPart _targetPart) {
		part = _targetPart;
	}

}
